#ifndef CHOOSEFRIENDDIALOG_H
#define CHOOSEFRIENDDIALOG_H

#include <QDialog>
#include <QWidget>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QScrollBar>
#include <QCheckBox>
#include <QLabel>
#include <QPushButton>
#include <QPainter>

#include "debug.h"
#include "model/datacenter.h"

////////////////////////////////////////
/// 选择好友对话框
////////////////////////////////////////

class ChooseFriendDialog : public QDialog
{
    Q_OBJECT
public:
    ChooseFriendDialog(QWidget* parent, const QString& userId);

    // 初始化左侧窗口
    void initLeftWindow(QHBoxLayout* layout);
    // 初始化右侧窗口
    void initRightWindow(QHBoxLayout* layout);
    // load data
    void initData();

    // 添加左侧好友元素
    void addFriendItem(const QString& userId, bool selected, const QIcon& avatar, const QString& name);
    // 添加右侧好友元素
    void addSelectedItem(const QString& userId, const QIcon& avatar, const QString& name);
    // 删除好友元素
    void deleteFriendItem(const QString& userId);

    QList<QString> generateMemberList();

private:
    QWidget* totalWidget;
    QWidget* selectWidget;

    QString userId;
};

////////////////////////////////////////
/// 选择好友元素
////////////////////////////////////////

class ChooseFriendItem : public QWidget
{
    Q_OBJECT
public:
    ChooseFriendItem(const QString& userId, ChooseFriendDialog* owner, bool selected, const QIcon& avatar, const QString& name);

    void paintEvent(QPaintEvent* event) override;
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;

    const QString& getUserId();
    QCheckBox* getCheckBox();

private:
    bool selected = false;

    QCheckBox* checkBox;
    QPushButton* avatarBtn;
    QLabel* nameLabel;

    QString userId;
};

#endif // CHOOSEFRIENDDIALOG_H
